package com.example.shardingdemo.config;


import com.example.shardingdemo.util.SnowFlakeUtil;
import org.apache.shardingsphere.core.strategy.keygen.SnowflakeShardingKeyGenerator;
import org.apache.shardingsphere.spi.keygen.ShardingKeyGenerator;

import java.util.Properties;
import java.util.concurrent.atomic.AtomicLong;

public class MyOrderShadingKeyGenerate implements ShardingKeyGenerator {

   static SnowFlakeUtil snowFlakeUtil = new SnowFlakeUtil();

    private SnowflakeShardingKeyGenerator snow = new SnowflakeShardingKeyGenerator();

    private AtomicLong atomic = new AtomicLong(0);

    @Override
    public Comparable<?> generateKey() {
        System.out.println("------执行了自定义主键生成器MyId-------");
        return snowFlakeUtil.nextId();
    }

    @Override
    public String getType() {
        return "MyKey";
    }

    @Override
    public Properties getProperties() {
        return null;
    }

    @Override
    public void setProperties(Properties properties) {

    }
}
